<div>
  <div>
    <% build_configuration = project.build_configuration || BuildConfiguration.new %>
    <%= form.fields_for :build_configuration, build_configuration do |bc_form| %>
      <div class="form-control mt-4">
        <%= render "shared/partials/radio_selector", selected: build_configuration.driver, options: [
          {
            icon: "skill-icons:docker",
            name: "project[build_configuration][driver]",
            label: "Local Docker",
            value: "docker",
            description: "Build images using Docker on the deployment server. Simple setup, suitable for smaller projects."
          },
          {
            icon: "/images/logo-compact.webp",
            name: "project[build_configuration][driver]",
            label: "Canine Cloud",
            value: "cloud",
            description: "We'll build the images for you on our servers, for free."
          },
          {
            icon: "skill-icons:kubernetes",
            name: "project[build_configuration][driver]",
            label: "Kubernetes Build Cloud",
            description: "Build images in your Kubernetes cluster. Scalable, distributed builds with better resource utilization.",
            value: "k8s",
            partial: "projects/build_configurations/k8s_build_cloud",
            locals: { current_account:, bc_form:, build_configuration: }
          }
        ].select { |option| BuildConfiguration::BUILDER_OPTIONS.include?(option[:value].to_sym) } %>
        
      </div>

      <div class="form-control mt-1 mb-2 w-full max-w-md">
        <label class="label">
          <span class="label-text">Build context directory</span>
        </label>
        <%= bc_form.text_field(
          :context_directory,
          class: "input input-bordered w-full focus:outline-offset-0",
          value: build_configuration.context_directory
        ) %>
        <label class="label">
          <span class="label-text-alt">Where should we run the build? Defaults to the root of the repository.</span>
        </label>
      </div>

      <div class="form-control mt-1 mb-2 w-full max-w-md">
        <label class="label">
          <span class="label-text">Credentials</span>
        </label>
        <%= bc_form.select(
          :provider_id,
          options_for_select(
            current_account.providers.has_container_registry.map do |provider|
              [provider.friendly_name, provider.id]
            end,
            selected: build_configuration.provider_id,
            disabled: current_account.providers.has_container_registry.select do |p|
              !current_user.providers.include?(p)
            end.map(&:id)
          ),
          { include_blank: "Select a provider..." },
          { class: "select select-bordered w-full" }
        ) %>
        <label class="label">
          <span class="label-text-alt">Select a credential that gives access to a container registry</span>
        </label>
      </div>

      <div data-controller="expandable-optional-input">
        <div>
          <a data-action="expandable-optional-input#show" class="btn btn-ghost">
            + Choose custom image registry
          </a>
        </div>

        <div data-expandable-optional-input-target="container">
          <div class="form-control mt-1 mb-2 w-full max-w-md">
            <label class="label">
              <span class="label-text">Image repository</span>
            </label>
            <%= bc_form.text_field(
              :image_repository,
              class: "input input-bordered w-full focus:outline-offset-0",
              value: build_configuration.image_repository,
              placeholder: "namespace/repo",
              pattern: "[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]/[a-zA-Z0-9._-]+",
              title: "Must be in the format 'namespace/repo'"
            ) %>
            <label class="label">
              <span class="label-text-alt">If this is left blank, a container registry will be automatically created for you.</span>
            </label>
          </div>
        </div>
      </div>

      <div class="form-control mt-4">
        <label class="label mb-2">
          <span class="label-text">Build method</span>
        </label>
        <%= render "shared/partials/radio_selector", selected: build_configuration.build_type || "dockerfile", options: [
          {
            icon: "skill-icons:docker",
            name: "project[build_configuration][build_type]",
            label: "Dockerfile",
            value: "dockerfile",
            description: "Build images using a Dockerfile. Traditional Docker build approach with full control over the build process.",
            partial: "projects/build_configurations/dockerfile_fields",
            locals: { bc_form:, build_configuration: }
          },
          {
            icon: "devicon:heroku",
            name: "project[build_configuration][build_type]",
            label: "Buildpacks",
            value: "buildpacks",
            description: "Use Cloud Native Buildpacks to automatically detect and build your application. No Dockerfile needed.",
            partial: "projects/build_configurations/buildpack_fields",
            locals: { bc_form:, build_configuration: }
          }
        ] %>
      </div>
    <% end %>
  </div>
</div>